import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.*;
import java.util.Scanner;

public class JDBC {
    public static void main(String[] args) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setUrl("jdbc:mysql://127.0.0.1:3306/except?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("040825lj");
        Scanner scanner = new Scanner(System.in);
        Connection connection = dataSource.getConnection();/*System.out.print("请输入id:");
        int id = scanner.nextInt();
        System.out.print("请输入name:");
        String name = scanner.next();*/
        String str = "select * from student";
        PreparedStatement statement = connection.prepareStatement(str);
        ResultSet resultSet = statement.executeQuery();
        while(resultSet.next()) {
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            System.out.println("id = " + id + " name = " + name);
        }
        resultSet.close();
        statement.close();;
        connection.close();
    }
}
